-
Notifications
You must be signed in to change notification settings - Fork 26
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
refactor(anta): Refactor VerifyInterfacesStatus test for nicer failure message #899
base: main
Are you sure you want to change the base?
refactor(anta): Refactor VerifyInterfacesStatus test for nicer failure message #899
Conversation
4d65a1d
to
33fea61
Compare
CodSpeed Performance ReportMerging #899 will not alter performanceComparing Summary
|
- If line protocol status is provided, prioritize checking against both status and line protocol status | ||
- If line protocol status is not provided and interface status is "up", expect both status and line protocol to be "up" | ||
- If interface status is not "up", check only the interface status without considering line protocol status | ||
This test performs the following checks for each specified interface: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can use numbered list but you need to put an extra indent.
709b125
to
2f22a23
Compare
Quality Gate failedFailed conditions See analysis details on SonarCloud Catch issues before they fail your Quality Gate with our IDE extension SonarLint |
@vitthalmagadum please fix the Sonarlint issue |
if TYPE_CHECKING: | ||
import sys | ||
|
||
if sys.version_info >= (3, 11): | ||
pass | ||
else: | ||
pass |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not required for now. Let's remove this.
This test performs the following checks for each specified interface: | ||
|
||
- If `line_protocol_status` is defined, both `status` and `line_protocol_status` are verified for the specified interface. | ||
- If `line_protocol_status` is not provided but the `status` is "up", it is assumed that both the interface and line protocol should be "up". |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- If `line_protocol_status` is not provided but the `status` is "up", it is assumed that both the interface and line protocol should be "up". | |
- If `line_protocol_status` is not provided but the `status` is "up", it is assumed that both the status and line protocol should be "up". |
for interface in self.inputs.interfaces: | ||
if (intf_status := get_value(command_output["interfaceDescriptions"], interface.name, separator="..")) is None: | ||
intf_not_configured.append(interface.name) | ||
self.result.is_failure(f"{interface.name} - not configured") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
self.result.is_failure(f"{interface.name} - not configured") | |
self.result.is_failure(f"{interface.name} - Not configured") |
@@ -261,18 +252,15 @@ def test(self) -> None: | |||
# If line protocol status is provided, prioritize checking against both status and line protocol status | |||
if interface.line_protocol_status: | |||
if interface.status != status or interface.line_protocol_status != proto: | |||
intf_wrong_state.append(f"{interface.name} is {status}/{proto}") | |||
actual_state = f"Expected: {interface.status}/{interface.line_protocol_status}, Actual: {status}/{proto}" | |||
self.result.is_failure(f"Interface status/Line protocol status for {interface.name} - {actual_state}") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
self.result.is_failure(f"Interface status/Line protocol status for {interface.name} - {actual_state}") | |
self.result.is_failure(f"{interface.name} - {actual_state}") |
if intf_wrong_state: | ||
self.result.is_failure(f"The following interface(s) are not in the expected state: {intf_wrong_state}") | ||
elif interface.status == "up" and (status != "up" or proto != "up"): | ||
self.result.is_failure(f"Interface status/Line protocol status for {interface.name} - Expected: up/up, Actual: {status}/{proto}") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
self.result.is_failure(f"Interface status/Line protocol status for {interface.name} - Expected: up/up, Actual: {status}/{proto}") | |
self.result.is_failure(f"{interface.name} - Expected: up/up, Actual: {status}/{proto}") |
elif interface.status == "up" and (status != "up" or proto != "up"): | ||
self.result.is_failure(f"Interface status/Line protocol status for {interface.name} - Expected: up/up, Actual: {status}/{proto}") | ||
elif interface.status != status: | ||
self.result.is_failure(f"Interface status for {interface.name} - Expected: {interface.status}, Actual: {status}") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
self.result.is_failure(f"Interface status for {interface.name} - Expected: {interface.status}, Actual: {status}") | |
self.result.is_failure(f"{interface.name} - Expected: {interface.status}, Actual: {status}") |
@@ -230,29 +235,15 @@ class Input(AntaTest.Input): | |||
interfaces: list[InterfaceState] | |||
"""List of interfaces with their expected state.""" | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here we need to keep a class variable to maintain the current behavior:
InterfaceState: ClassVar[type[InterfaceState]] = InterfaceState
Description
Refactor VerifyInterfacesStatus test for nicer failure message
Fixes #587
Checklist:
pre-commit run
)tox -e testenv
)